package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.SysAppConfig;
import com.pureut.system.domain.dto.SysAppConfigDto;
import com.pureut.system.domain.vo.SysAppConfigVo;
import com.pureut.system.domain.vo.SysAuditHistoryVo;
import com.pureut.system.service.ISysAppConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 审核控制层
 * @Param
 * @Date 22-12-08
 * @Author hl
 **/
@RestController
@RequestMapping("/appconfig")
public class SysAppConfigController extends BaseController {

    @Autowired
    private ISysAppConfigService sysAppConfigService;

    /**
     * 获取审核配置
     */
    @RequiresPermissions("approval:appconfig:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAppConfigVo sysAppconfigVo)
    {
        startPage();
        List<SysAppConfigDto> list = sysAppConfigService.selectAppConfigList(sysAppconfigVo);
        return getDataTable(list);
    }

    /**
     * 新增审核信息
     */
    @RequiresPermissions("system:appconfig:add")
    @Log(title = "新增审核信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysAppConfig SysAppConfig) throws Exception {
        return toAjax(sysAppConfigService.insertAppConfig(SysAppConfig));
    }

    /**
     * 删除审核信息
     */
    @RequiresPermissions("system:appconfig:remove")
    @Log(title = "删除审核信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{appconfigId}")
    public AjaxResult remove(@PathVariable("appconfigId") String appconfigId) throws Exception {
        return toAjax(sysAppConfigService.deleteSysAppconfig(appconfigId));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("system:appconfig:query")
    @GetMapping(value = "/{appId}")
    public AjaxResult getAppInfo(@PathVariable long appId)
    {
        return AjaxResult.success(sysAppConfigService.getAppconfigInfo(appId));
    }

    /**
     * 修改审核信息
     */
    @RequiresPermissions("system:appconfig:edit")
    @Log(title = "审核配置", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysAppConfig SysAppConfig) throws Exception {
        return toAjax(sysAppConfigService.updateAppConfigEdit(SysAppConfig));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/detail")
    public TableDataInfo getTheDetail(long appId)
    {
        startPage();
        return getDataTable(sysAppConfigService.getTheDetail(appId));
    }


    /**
     * 根据权限码进行审核
     */
    @GetMapping(value = "/sequence")
    public AjaxResult getSequence(SysAuditHistoryVo sysAuditHistoryVo) throws Exception
    {
        return AjaxResult.success(sysAppConfigService.getSequence(sysAuditHistoryVo));
    }

    /**
     * 根据权限码获取审核历史
     */
    @GetMapping(value = "/history")
    public AjaxResult getAuditHistory(SysAuditHistoryVo sysAuditHistoryVo)
    {
        return AjaxResult.success(sysAppConfigService.getAuditHistory(sysAuditHistoryVo));
    }

    /**
     * 修改审核类型
     */
    @PutMapping("/editHistory")
    public AjaxResult editHistory(@RequestBody SysAuditHistoryVo sysAuditHistoryVo) {
        return toAjax(sysAppConfigService.updateHistoryAppConfigEdit(sysAuditHistoryVo));
    }


}
